package com.tangguo.vshop.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tangguo.vshop.domain.Customer;
import com.tangguo.vshop.repository.CustomerRepository;
import com.tangguo.vshop.security.JwtUser;

@RestController 
@RequestMapping("/customer")
public class CustomerController {
	@Autowired
	private CustomerRepository customerRepository;
	
	@RequestMapping("/search")
	public Page<Customer> search(String keywords,Pageable pageable){
		JwtUser jwtUser = (JwtUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		if(keywords==null||"".equals(keywords)){
			return customerRepository.findByMainbody(jwtUser.getMainbodyId(),pageable);
		}
		return customerRepository.findByHelpcodeLikeOrNameLike(keywords,keywords,pageable);

	}
}
